package com.lw.sbdemo2.mapper;

import com.lw.sbdemo2.common.base.BaseMapper;
import com.lw.sbdemo2.entity.TkUserAnswerExamRecord;
import com.lw.sbdemo2.entity.TkUserErrorExamDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>标题: 用户试卷记录表服务 - 数据交互层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-4-14
 */
@Mapper
public interface TkUserAnswerExamRecordMapper extends BaseMapper<TkUserAnswerExamRecord> {

	/**
     * 分页获取用户试卷记录表列表
     *
     * @param query 搜索关键词
	 * @param tkUserAnswerExamRecord 查询实体
     * @return 用户列表
     */
    List<TkUserAnswerExamRecord> findListPage(@Param("query") String query, @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 获取用户答题排名
	 *
	 * @param tkUserAnswerExamRecord 查询实体
	 * @return 用户列表
	 */
	List<TkUserAnswerExamRecord> getRankList( @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 获取用户答题率排名
	 *
	 * @param tkUserAnswerExamRecord 查询实体
	 * @return 用户列表
	 */
	List<TkUserAnswerExamRecord> getRankRateList( @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 获取老师班级下用户答题排名
	 *
	 * @param tkUserAnswerExamRecord 查询实体
	 * @return 用户列表
	 */
	List<TkUserAnswerExamRecord> getTeacherRank( @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 获取老师班级下用户学习答题准确率排名
	 *
	 * @param tkUserAnswerExamRecord 查询实体
	 * @return 用户列表
	 */
	List<TkUserAnswerExamRecord> getTeacherRateRank( @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 获取用户答题排名
	 *
	 * @param tkUserAnswerExamRecord 查询实体
	 * @return 用户列表
	 */
	List<TkUserAnswerExamRecord> getGradeRank( @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

	/**
	 * 导出用户答题数据
	 * @param sysList
	 * @param classId
	 * @return
	 */
	List<TkUserAnswerExamRecord> exportUserAnswer(@Param("sysList") List<String> sysList , @Param("model") TkUserAnswerExamRecord tkUserAnswerExamRecord);

    /**
     * 获取用户排名
     * @param examId
     * @param answerScore
     * @return
     */
	@Select("SELECT count(1) FROM tk_user_answer_exam_record t, tk_user_info a WHERE  a.USER_ID = t.USER_ID and a.TEACHER_ID = #{teacherId} and t.exam_id = #{examId} and t.answer_score > #{answerScore}")
	Long getUserRank(@Param("examId") String examId, @Param("answerScore") BigDecimal answerScore , @Param("teacherId") String teacherId);

	/**
	 * 获取用户排名
	 * @param examId
	 * @param answerScore
	 * @return
	 */
	@Select("SELECT count(1) FROM tk_user_answer_exam_record t, tk_user_info a WHERE a.USER_ID = t.USER_ID and t.exam_id = #{examId} and a.TEACHER_ID = #{teacherId} and t.EXACT_RATE > #{answerScore}")
	Long getUserRateRank(@Param("examId") String examId, @Param("answerScore") BigDecimal answerScore, @Param("teacherId") String teacherId);
}
